package com.tvshows.repository;


import com.tvshows.domain.Historique;
import com.tvshows.domain.Show;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
import org.springframework.data.mongodb.repository.support.SimpleMongoRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.util.Assert;


import java.io.Serializable;
import java.util.List;

/**
 * Created by Tangi on 06/03/2015.
 */
public class HistoriqueRepositoryImpl  implements  CustomHistoriqueRepository  {

    private final MongoOperations operations;

    @Autowired
    public HistoriqueRepositoryImpl(MongoOperations operations) {
        Assert.notNull(operations, "MongoOperations must not be null!");
        this.operations = operations;
    }

    @Override
    public void add(Show t) {
        Historique h = new Historique();
        h.setDateUpdated(new DateTime());
        h.setShowId(t.getId());
        this.operations.save(h);


    }

    @Override
    public List<Historique> findByShow(String showId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("showId").is(showId));
        return this.operations.find(query, Historique.class);
    }
}
